package devbureau.fstore.common.translate.impl;

import devbureau.fstore.common.TranslatorItem;

/**
 *
 * @author buyakov
 */
public class HelperFileParser {


    public static final String EMPTY_STR = "";

	public static final Integer NAME = 0;
	public static final Integer NAME_RU = 1;

    
    public static TranslatorItem parseData(String[] data) throws Exception {

     		TranslatorItem item = null;

			String name = "";
			String nameRU = "";

			String errorMsg = "";

			// check provider
			name = data[NAME].trim();
			if(name == null || EMPTY_STR.equals(name)) {
				errorMsg+= "\n'Первая колонка' обязательное поле";
			}

			// check name
            nameRU = "";
            if(data.length > 1 && data[NAME_RU] != null) {
                nameRU = data[NAME_RU].trim();
            }
            
			if(errorMsg.isEmpty()) {
				item = new TranslatorItem(name,nameRU);
			}else{
				throw new Exception("Ошибка при разборе строки : " + errorMsg);
			}

            return item;
    }
}
